//
//  Const.swift
//  XMLYFM
//
//  Created by Domo on 2018/7/31.
//  Copyright © 2018年 知言网络. All rights reserved.
//

import Foundation
import UIKit
import SnapKit
import SwiftyJSON
import HandyJSON
import SwiftMessages

let YYScreenWidth = UIScreen.main.bounds.size.width
let YYScreenHeigth = UIScreen.main.bounds.size.height
let DominantColor = UIColor.init(red: 242/255.0, green: 77/255.0, blue: 51/255.0, alpha: 1)
let FooterViewColor = UIColor.init(red: 240/255.0, green: 241/255.0, blue: 244/255.0, alpha: 1)

// iphone X
let isIphoneX = YYScreenHeigth == 812 ? true : false
// navigationBarHeight
let navigationBarHeight : CGFloat = isIphoneX ? 88 : 64
// tabBarHeight
let tabBarHeight : CGFloat = isIphoneX ? 49 + 34 : 49

var topVC: UIViewController? {
    var resultVC: UIViewController?
    resultVC = _topVC(UIApplication.shared.keyWindow?.rootViewController)
    while resultVC?.presentedViewController != nil {
        resultVC = _topVC(resultVC?.presentedViewController)
    }
    return resultVC
}

//var isIphoneX: Bool {
//    return UI_USER_INTERFACE_IDIOM() == .phone
//        && (max(UIScreen.main.bounds.height, UIScreen.main.bounds.width) == 812
//            || max(UIScreen.main.bounds.height, UIScreen.main.bounds.width) == 896)
//}

private  func _topVC(_ vc: UIViewController?) -> UIViewController? {
    if vc is UINavigationController {
        return _topVC((vc as? UINavigationController)?.topViewController)
    } else if vc is UITabBarController {
        return _topVC((vc as? UITabBarController)?.selectedViewController)
    } else {
        return vc
    }
}

extension NSObject{
    
    //MARK: print
    func YYNSLog<T>(_ message: T, file: String = #file, function: String = #function, lineNumber: Int = #line) {
        #if DEBUG
        let fileName = (file as NSString).lastPathComponent
        print("[\(fileName):funciton:\(function):line:\(lineNumber)]- \(message)")
        #endif
    }

    
}

